import path from "path"
import * as glob from "glob"
import { desktopPath } from "@/utils"
import { email } from "@/services"

import { type Tasks } from "@/interface"

export default async (tasks: Tasks[], threshold: number) => {
  for (const task of tasks) {
    const { folder } = task
    const courses = glob.sync(path.join(desktopPath, `t_${folder}`, "*/"), {
      windowsPathsNoEscape: true,
    })

    if (courses.length <= threshold) {
      await email({
        folder: folder,
        subject: `${folder} 资料剩余 ${courses.length}个，请及时补充`,
        text: "",
      })
    }
  }
}
